package com.gxk.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.gxk.res.PublicConst;
import com.gxk.stage.GameoverStage;
import com.gxk.stage.MainStage;

public class MainScreen extends ScreenAdapter {

	private MainStage mainStage;
	private GameoverStage gameOverStage;

	private Viewport viewport;

	public MainScreen() {
		this.create();
	}

	private void create() {
		mainStage = new MainStage(this);
		gameOverStage = new GameoverStage();
		this.setViewPort();
	}

	public void gameOverStageInit() {
		this.gameOverStage.reStart();
	}

	private void setViewPort() {
		Gdx.graphics.setDisplayMode(PublicConst.WORLD_WIDTH,
				PublicConst.WORLD_HEIGHT, false);
		viewport = mainStage.getViewport();
		viewport.setWorldSize(PublicConst.WORLD_WIDTH, PublicConst.WORLD_HEIGHT);
		viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
		mainStage.setViewport(viewport);
		gameOverStage.setViewport(viewport);
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(1, 1, 1, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		mainStage.act();
		mainStage.draw();

		if (mainStage.getGameState() == 1) {
			gameOverStage.act();
			gameOverStage.draw();
		}

		super.render(delta);
	}
}
